
import http, { baseHeaders, baseParams } from "@/utils/request";
import { UrlGetCoins } from "@/utils/apiUrl";
import { isEmptyString } from "@/utils/utils";
import { Toast } from "antd-mobile";

/**
 * 获取币种信息
 * @returns thunk
 */
export const getCoins = (reqCallback) => {
    return async (dispatch) => {
        console.log("getCoins: " + UrlGetCoins);

        //组装参数
        const params = baseParams();
        const headers = baseHeaders();
        console.log(headers)

        //发起请求
        const res = await http.post(UrlGetCoins, params, headers)
        const resCode = parseInt(res.code)
        const resObj = res.data
        console.log("获取币种信息-结束：=======" + resCode)
        console.log(resObj)
        console.log("获取币种信息-结束：=======")

        //保存
        const success = (resCode === 0)

        //如果有错误，提示
        if (!success) {
            if (!isEmptyString(res.msg)) {
                Toast.show(res.msg, 1)
            }
        }

        //回调
        reqCallback && reqCallback(success, resObj)
    }
}
